package com.atde._05_behavioral_design_patterns.observer.internetweather;


/**
 * @BelongsProject: hsp_java_design_mode
 * @BelongsPackage: com.atde._05_behavioral_design_patterns.observer.internetweather
 * @Author: Del
 * @CreateTime: 2025-06-29  19:32
 * @Description: 此类为核心类，包含最新的天气情况
 * 它含有 CurrentConditions 对象
 * 当数据有更新时，就主动调用 CurrentConditions 对象 update 方法（含有 display 操作），这样接入方就可以得到通知，并更新自己
 * @Version: 1.0
 */
public class WeatherData {

    // 天气情况
    private float temperature;
    private float presure;
    private float humidity;
    private CurrentConditions currentConditions;

    public WeatherData(CurrentConditions currentConditions) {
        this.currentConditions = currentConditions;
    }

    public float getTemperature() {
        return temperature;
    }

    public void setTemperature(float temperature) {
        this.temperature = temperature;
    }

    public float getPresure() {
        return presure;
    }

    public void setPresure(float presure) {
        this.presure = presure;
    }

    public float getHumidity() {
        return humidity;
    }

    public void setHumidity(float humidity) {
        this.humidity = humidity;
    }

    public void dataChange() {
        // 当数据有更新时，就调用 setData，然后通知到各个注册的观察者，使它们能够更新自己
        currentConditions.update(getTemperature(), getPresure(), getHumidity());
    }

    public void setData(float temperature, float presure, float humidity) {
        this.temperature = temperature;
        this.presure = presure;
        this.humidity = humidity;
        // 调用 dataChange，将最新的信息推送给各个注册的观察者
        dataChange();
    }
}
